<template>
	<view class="container">
		<uni-card v-for="item,index in commentlist" 
		:title="'用户:'+item.userId+''"  
		:extra="item.postDate"
		note="Tips">{{item.comment}}
		</uni-card>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				foodid: 1,
				pageIndex: 0,
				pageSize: 4,
				commentlist: [{
					"id": 29,
					"comment": "sadf",
					"foodId": 1,
					"postDate": "2024-03-15",
					"userId": "22"
				}]
			}
		},
		methods: {
			reload() {
				uni.request({
					url: this.$baseUrl+'comments/getCommentsByFoodIdByPage',
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					data: {
						foodid: this.foodid || 1,
						pageIndex: 1,
						pageSize: this.pageSize
					},
					success: res => {
						this.commentlist = res.data.data.content
						console.log(this.commentlist);

					},
					fail: (err) => {
						console.log(err);
					},
					complete: () => {
						uni.stopPullDownRefresh()
					}
				});
			},
			loadmore() {
				this.pageIndex = this.pageIndex + 1
				uni.request({
					url: this.$baseUrl+'comments/getCommentsByFoodIdByPage',
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					data: {
						foodid: this.foodid || 1,
						pageIndex: this.pageIndex,
						pageSize: this.pageSize
					},
					success: res => {
						this.commentlist = this.commentlist.concat(res.data.data.content)
						console.log(this.commentlist);

					},
					fail: (err) => {
						console.log(err);
					},
					complete: () => {
						uni.hideLoading()
					}
				});
			}
		},
		onPullDownRefresh() {
			this.reload()
		},
		onReachBottom() {
			uni.showLoading()
			setTimeout(() => {
				this.loadmore()
			}, 1000);
		},
		onLoad() {
			this.reload()
		}
	}
</script>

<style>

</style>